package com.lsa.helpers.graph;

import java.io.File;
import java.io.IOException;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.apache.commons.io.FileUtils;

public class TestTgfGraph extends TestCase
{
    public void testGraphReadWrite(){
    	try {
    		IGraph<String, String> graph = TgfGraphFactory.readGraphFromFile("data/binaryTree25.tgf", new DefaultToStringConverter(), new DefaultToStringConverter(), true);
    		assertNotNull(graph);
    		assertEquals(graph.nodeCount(), 25);
    		assertEquals(graph.edgeCount(), 24);
    		TgfGraphFactory.saveGraphAsTgf(graph, new DefaultToStringConverter(), new DefaultToStringConverter(), "data/gen/tmp.tgf");
    		Assert.assertEquals(FileUtils.readFileToString(new File("data/binaryTree25.tgf")), FileUtils.readFileToString(new File("data/gen/tmp.tgf")));
    		
		} catch (IOException e) {
		    System.out.println(e);
			assertFalse(true);
		}
    }
    
    public void atestGraphWrite() throws IOException {
        AdjGraph<String, String> g = new AdjGraph<String, String>(true, 0, "");
        for (int i = 0; i < 11; i++) {
            g.addNode(""+i);
        }
        g.addEdge(0, 1);
        g.addEdge(1, 2);
        g.addEdge(2, 3);
        g.addEdge(3, 4);
        g.addEdge(4, 5);
        
        g.addEdge(1, 6);
        g.addEdge(6, 7);
        g.addEdge(7, 5);
        g.addEdge(7, 9);
        g.addEdge(6, 8);
        g.addEdge(8, 9);
        g.addEdge(8, 10);
        
        TgfGraphFactory.saveGraphAsTgf(g, new DefaultToStringConverter(), new DefaultToStringConverter(), "data/graph/small_tmp.tgf");
    }
}
